package com.hghivln.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hghivln.constants.Constants;
import com.hghivln.mapper.InventoryLogMapper;
import com.hghivln.pojo.domain.InventoryLog;
import com.hghivln.pojo.dto.InventoryLogDto;
import com.hghivln.pojo.vo.AjaxResult;
import com.hghivln.service.InventoryLogService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class InventoryLogServiceImpl implements InventoryLogService {

    @Autowired
    private InventoryLogMapper inventoryLogMapper;

    @Override
    public AjaxResult listInventoryLogForPage(InventoryLogDto inventoryLogDto) {
        Page<InventoryLog> page = new Page<>(inventoryLogDto.getPageNum(), inventoryLogDto.getPageSize());
        QueryWrapper<InventoryLog> qw = new QueryWrapper<>();
        qw.like(StringUtils.isNotBlank(inventoryLogDto.getPurchaseId()),InventoryLog.COL_PURCHASE_ID,inventoryLogDto.getPurchaseId());
        qw.like(StringUtils.isNotBlank(inventoryLogDto.getMedicinesName()), InventoryLog.COL_MEDICINES_NAME, inventoryLogDto.getMedicinesName());
        qw.eq(StringUtils.isNotBlank(inventoryLogDto.getMedicinesType()), InventoryLog.COL_MEDICINES_TYPE, inventoryLogDto.getMedicinesType());
        qw.eq(StringUtils.isNotBlank(inventoryLogDto.getProducterId()), InventoryLog.COL_PRODUCTER_ID, inventoryLogDto.getProducterId());
        qw.eq(StringUtils.isNotBlank(inventoryLogDto.getPrescriptionType()), InventoryLog.COL_PRESCRIPTION_TYPE, inventoryLogDto.getPrescriptionType());

        qw.ge(inventoryLogDto.getBeginTime() != null, InventoryLog.COL_CREATE_TIME, inventoryLogDto.getBeginTime());
        qw.le(inventoryLogDto.getEndTime() != null, InventoryLog.COL_CREATE_TIME, inventoryLogDto.getEndTime());
        qw.eq(InventoryLog.COL_DEL_FLAG, Constants.DEL_FALSE);
        qw.orderByDesc(InventoryLog.COL_CREATE_TIME);
        inventoryLogMapper.selectPage(page, qw);
        return AjaxResult.success("查询成功", page.getRecords(), page.getTotal());
    }
}

